<cfcomponent output="false">
	
	<!---  --->
	
	<cffunction name="saveFund" access="public" output="true" returntype="string">
		<cfargument name="id" required="false" default="" />
		<cfargument name="title" required="true" />
		<cfargument name="who" required="true" />
		<cfargument name="description" required="true" />
		<cfargument name="end_date" required="false" default="" />
		<cfargument name="amount" required="false" default="" />
		<cfargument name="private" required="false" default="0" />
	
		<cfset var local = {} />

		<cfif session.userID eq -1>
			<cfset application.q.addMessage("Please log in or create an account.") />
		<cfelse>
			<cftry>
				<!--- check arguments --->
				<cfset local.userID = application.q.decrypt(session.userID)>
				<cfif arguments.title eq "" or arguments.who eq "" or arguments.description eq "">
					<cfthrow message="Missing required data." />
				</cfif>
				<cfif arguments.end_date neq ''>
					<cfset arguments.end_date=application.q.formatDate(arguments.end_date) />
				</cfif>
				
				<cfset application.q.dbSave(
					table="fund",
					id=arguments.id,
					user_id=local.userID,
					title=arguments.title,
					who=arguments.who,
					description=arguments.description,
					end_date=arguments.end_date,
					private=arguments.private,
					amount=arguments.amount
				) />
				
				<cfcatch>
					<cfset application.q.addMessage("Error saving Fund. #cfcatch.message#") />
					<cfreturn 0 />
				</cfcatch>
			</cftry>
			<cfset application.q.addMessage("Fund Created.") />
			<cfreturn 1 />
		</cfif>

	</cffunction>
	
	<!--- --->
	
	<cffunction name="getFunds" access="public" output="true" returntype="query">
	
		<cfreturn application.g.fundGateway.getFunds(argumentCollection=arguments) />
		
	</cffunction>
	
	<!--- --->
	
</cfcomponent>